home *** CD-ROM | disk | FTP | other *** search
- #include <A4Stuff.h>
- #include <Devices.h>
- #include "CDEVClass.h"
-
- // declared in CDEV.c
- extern long runable(void);
- extern cdevObj *makeCDEV(short numItems,DialogPtr cp);
-
- // main entry point for control panel
- pascal long main(short message,short item,short numItems,short privateValue,
- EventRecord *e,cdevObj *cdev,DialogPtr d)
- {
- // set up a4 so we can access the globals
- long oldA4=SetCurrentA4();
-
- // return code
- long result=0;
-
- switch (message) {
- // do initialization
- case initDev:
- if ((long)cdev == cdevUnset)
- cdev=makeCDEV(numItems,d);
- break;
-
- // control panel is closing
- case closeDev:
- result=cdevUnset;
- break;
-
- // can we run? return 1 if so, else 0
- case macDev:
- result=runable();
- break;
-
- // it's not an init, open, or close message
- default:
- if ((long)cdev != cdevUnset) {
- // copy over this event and call the action proc
- cdev->e=e;
- result=cdev->actions(message,item);
- }
- break;
- }
-
- // if there is no error code then make sure we return
- // the cdev as the result, as per IM:MMT pg 8-30
- if (result == 0)
- result=(long)cdev;
- else {
- // there's either an err, or we are closing. In either case, delete the cdev
- delete cdev;
-
- // if we are deleting then result is cdevUnset and there is no err. Otherwise it
- // must be an error code returned by one of the functions. Set the result to 1
- // to error out
- if (result != cdevUnset)
- result=1;
- }
-
- // restore a4 before exiting
- SetA4(oldA4);
-
- return(result);
- }